home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / buffr2.zip / BD2ARRAY.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  3KB  |  107 lines

  1. Unit BD2Array;  {Useable 2-Dimensional BufferedArrays}
  2. {$R-}
  3.  
  4. INTERFACE
  5. Uses BD2_Max;
  6.  
  7. Type
  8.   BD2_IntArray = Object (D2_BufferedArray)
  9.  
  10.                    Procedure Init (Max1,Max2,MaxBuffSize : LongInt;
  11.                                   FileName : String);
  12.  
  13.                    { BD2_xxxArrays are indexed 0..Max1-1, 0..Max2-1}
  14.  
  15.                    Procedure Load (FileName : String;
  16.                                    Max1,Max2,MaxBuffSize : LongInt);
  17.  
  18.                    Procedure Accept (X,Y : LongInt; I : Integer);
  19.  
  20.                    Procedure Retrieve (X,Y : LongInt; Var I : Integer);
  21.  
  22.                    {NOTE: There is no reason why Retrieve could not be}
  23.                    {redefined as a function for atomic types such as Integer}
  24.  
  25.                    Procedure Copy (From : BD2_IntArray);
  26.                               {Target *MUST* already be initialized}
  27.                               {to the EXACT same parameters as From}
  28.                               {this will save checking for sufficient}
  29.                               {available Memory!}
  30.  
  31. (* no redefinition needed
  32.  
  33.                    Procedure Store;
  34.  
  35.                    Procedure Swap (X1,Y1,X2,Y2 : LongInt);
  36.                               {Swap the 1 and 2 Element}
  37.  
  38.                    Function MaxIndex (Index : Byte) : LongInt;
  39.                                      {Return the Max legal Index}
  40.                                      {for the Indexth Dimension}
  41.  
  42.                    Function MaxSize : LongInt;
  43.                                       {Report Number of Array Elements}
  44.                    Function ElemSize : Word;  {Report Element Size}
  45.                    Procedure Destroy;
  46. *)
  47.           End; {BD2_IntArray}
  48.  
  49. IMPLEMENTATION
  50.  
  51. Uses BND_Max;  {Obtain the definition of the DimensionPtr Type}
  52.  
  53. Procedure BD2_IntArray.Init;
  54. {NOTE: If ANY of the Max's is zero, ND_MAX.INIT will attempt}
  55. {to determine and allocate the maximum possible index.  If all}
  56. {are zero, then the largest possible evenly-indexed array will be allocated}
  57. {There is a POSSIBILITY of allocation errors if less than all are}
  58. {zero, but such errors will be detected and reported}
  59. Var
  60.   Temp : DimensionPtr;
  61.   I    : Byte;
  62. Begin
  63.   I := 0;
  64.   GetMem (Temp,2*SizeOf(LongInt));
  65.   Temp^[I] := Max1; I := 1;  {Have to fool the compiler, even}
  66.   Temp^[I] := Max2;          {with Range-checking off!!}
  67.   D2_BufferedArray.Init (Temp,SizeOf(Integer),MaxBuffSize,FileName);
  68.   FreeMem (Temp,2*SizeOf(LongInt));
  69. End;
  70.  
  71. Procedure BD2_IntArray.Load;
  72. Var
  73.   Temp : DimensionPtr;
  74.   I    : Byte;
  75. Begin
  76.   I := 0;
  77.   GetMem (Temp,2*SizeOf(LongInt));
  78.   Temp^[I] := Max1; I := 1;  {Have to fool the compiler, even}
  79.   Temp^[I] := Max2;          {with Range-checking off!!}
  80.   D2_BufferedArray.Load (FileName,SizeOf(Integer),MaxBuffSize,2,Temp);
  81.   FreeMem (Temp,2*SizeOf(LongInt));
  82. End;
  83.  
  84. Procedure BD2_IntArray.Accept (X,Y : LongInt; I : Integer);
  85. Var
  86.   Temp : Integer;
  87. Begin
  88.   Temp := I;
  89.   D2_BufferedArray.Accept (X,Y,Temp,SizeOf(Integer))
  90. End;
  91.  
  92. Procedure BD2_IntArray.Retrieve (X,Y : LongInt; Var I : Integer);
  93. Var
  94.   Temp : Integer;
  95. Begin
  96.   D2_BufferedArray.Retrieve (X,Y,Temp,SizeOf(Integer));
  97.   I := Temp
  98. End;
  99.  
  100. Procedure BD2_IntArray.Copy (From : BD2_IntArray);
  101. {Redefined purely for type-checking}
  102. Begin
  103.   D2_BufferedArray.Copy (From)
  104. End;
  105.  
  106. BEGIN
  107. END.